package com.example.liaotian.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.example.liaotian.Bean.Post;
import com.example.liaotian.R;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;

/**
 * 帖子界面
 */

public class ReciveActivity extends Activity {

    private TextView title,content,nikename,time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//设置隐藏顶部标题栏
        setContentView(R.layout.activity_recive);

        initView();
        initData();
    }

    private void initData() {
        //这种方法是把数据全部用intent携带，然后在这里拿出复制
        //建议用这种预加载的模式
        Intent intent1 = getIntent();
        String nikename1 = intent1.getStringExtra("nikename");
        String content1 = intent1.getStringExtra("content");
        String time1 = intent1.getStringExtra("time");
        String title1 = intent1.getStringExtra("title");

        nikename.setText(nikename1);
        content.setText(content1);
        time.setText(time1);
        title.setText(title1);
//
//        //从intent取出携带的id
//        Intent intent =getIntent();
//        String id = intent.getStringExtra("id");
//        //用bmob的查询方法以id为载体查找到数据
//        BmobQuery<Post> query = new BmobQuery<>();
//        query.getObject(id, new QueryListener<Post>() {
//            @Override
//            //如果没有异常就把数据填入，有异常就弹出提示框
//            public void done(Post post, BmobException e) {
//                if (e == null){
//                    nikename.setText(post.getNikename());
//                    content.setText(post.getContent());
//                    time.setText(post.getCreatedAt());
//                    title.setText(post.getTitle());
//                }else {
//                    Toast.makeText(ReciveActivity.this,"获取失败",Toast.LENGTH_SHORT).show();
//                }
//            }
//        });

    }

    private void initView() {

        title = findViewById(R.id.title);
        content = findViewById(R.id.content);
        //设置textview可以上下滑动，需要在布局文件中添加  android:scrollbars="vertical"
        content.setMovementMethod(ScrollingMovementMethod.getInstance());
        nikename = findViewById(R.id.nikename);
        time = findViewById(R.id.time);

    }
}
